//
//  ZFTabbarViewController.m
//  HappilyLoan
//
//  Created by zainishenbian on 2017/4/14.
//  Copyright © 2017年 zongqingxiangqian. All rights reserved.
//

#import "ZFTabbarViewController.h"
#import "ZFHeader.h"

@interface ZFTabbarViewController ()<UITabBarDelegate,UITabBarControllerDelegate>

@end

@implementation ZFTabbarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.delegate = self;
}
#pragma mark ———— tabbarcontroller delegae
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
{
    if ([viewController.tabBarItem.title isEqualToString:@"首页"]) {
        
        tabBarController.selectedIndex = 0;
    }
    if ([viewController.tabBarItem.title isEqualToString:@"消息"]) {
        
        if (![ZFLoginConfig isLogined]) {
            
            UIViewController *loginVC = [ZFLoginConfig getLoginVC2];
            [self presentViewController:loginVC animated:YES completion:nil];
            return NO;
        }
        tabBarController.selectedIndex = 1;
    }
    if ([viewController.tabBarItem.title isEqualToString:@"账单"]) {
        
        if (![ZFLoginConfig isLogined]) {
            
            UIViewController *loginVC = [ZFLoginConfig getLoginVC2];
            [self presentViewController:loginVC animated:YES completion:nil];
            return NO;
        }

        tabBarController.selectedIndex = 2;
    }
    if ([viewController.tabBarItem.title isEqualToString:@"贷款超市"]) {
        
        if (![ZFLoginConfig isLogined]) {
            
            UIViewController *loginVC = [ZFLoginConfig getLoginVC2];
            [self presentViewController:loginVC animated:YES completion:nil];
            return NO;
        }
        
        tabBarController.selectedIndex = 2;
    }

    if ([viewController.tabBarItem.title isEqualToString:@"我的"]) {
        
        tabBarController.selectedIndex = 3;
    }

//    if (![viewController.tabBarItem.title isEqualToString:@"首页"] || ![viewController.tabBarItem.title isEqualToString:@"我的"]) {
//        
//        if (![ZFLoginConfig isLogined]) {
//            
//            UIViewController *loginVC = [ZFLoginConfig getLoginVC2];
//            [self presentViewController:loginVC animated:YES completion:nil];
//            return NO;
//        }
//    }
    
    return YES;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
